package com.redwolfsoft.libshoppingserver.brand;

import net.sf.json.JSONObject;

public class Story {
	public int id = -1;
	public String title = null;
	public String brief = null;
	public String datetime = null;
	public int numComments = 0;
	public String picUrl = null;//在服务器端若有则赋值，没有则置为null
	//客户端检查其值，若有则显示出来;若为null则忽略
	public String detailUrl = null;
	
	public Story(int id,String title, String brief,String datetime
			,int numComments,String picUrl,String detailUrl)
	{
		this.id=id;
		this.title=title;
		this.brief=brief;
		this.datetime=datetime;
		this.numComments=numComments;
		this.picUrl=picUrl;
		this.detailUrl=detailUrl;
	}
	
	public Story(JSONObject obj)
	{
		if(obj==null)
		{
			//Log.w(TAG, "JSONObject is null");
			return;
		}
		//try {	
			id=obj.getInt("id");
			title = obj.getString("title");
			brief = obj.getString("brief");
			datetime = obj.getString("datetime");				
			numComments = obj.getInt("numComments");
			picUrl = obj.optString("picUrl");
			detailUrl = obj.optString("detailUrl");
		/*} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}*/
	}
	
	public JSONObject toJsonObject()
	{
		JSONObject obj = new JSONObject();
		//JSONObject obj2 = new JSONObject();
		//try {
			obj.put("id", id);
			obj.put("title", title);
			obj.put("brief", brief);
			obj.put("datetime", datetime);
			obj.put("numComments", numComments);
			obj.put("picUrl", picUrl);
			obj.put("detailUrl", detailUrl);
				//obj2.put(PRICE_INFO_TAG, obj);
			/*} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return null;
			}*/
			return obj;
			
	}
}
